import 'package:bitcoin_mine/model/mine_info.dart';

class RegisterModel {
  String access_token;
  String token_type;
  int expires_in;
  User user;
  String version;

  RegisterModel({
    required this.access_token,
    required this.token_type,
    required this.expires_in,
    required this.user,
    required this.version,
  });

  factory RegisterModel.fromJson(Map<String, dynamic> json) {
    return RegisterModel(
      access_token: json['access_token'],
      token_type: json['token_type'],
      expires_in: json['expires_in'],
      user: User.fromJson(json['user']),
      version: json['version'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'access_token': access_token,
      'token_type': token_type,
      'expires_in': expires_in,
      'user': user.toJson(),
      'version': version,
    };
  }
}

class User {
  int account;
  int status;
  String register_at;
  String refer;
  String product_id;
  String partner_id;
  String pitcher_id;
  String app_id;
  int uid;
  String updated_at;
  String created_at;
  int id;
  User_info? user_info;
  Apple_user? apple_user;

  User({
    required this.account,
    required this.status,
    required this.register_at,
    required this.refer,
    required this.product_id,
    required this.partner_id,
    required this.pitcher_id,
    required this.app_id,
    required this.uid,
    required this.updated_at,
    required this.created_at,
    required this.id,
    this.user_info,
    this.apple_user,
  });

  factory User.empty() {
    return User(
      account: 0,
      status: 0,
      register_at: '',
      refer: '',
      product_id: '',
      partner_id: '',
      pitcher_id: '',
      app_id: '',
      uid: 0,
      updated_at: '',
      created_at: '',
      id: 0,
    );
  }

  factory User.fromJson(Map<String, dynamic> json) {
    return User(
      account: json['account'],
      status: json['status'],
      register_at: json['register_at'],
      refer: json['refer'],
      product_id: json['product_id'].toString(),
      partner_id: json['partner_id'].toString(),
      pitcher_id: json['pitcher_id'].toString(),
      app_id: json['app_id'].toString(),
      uid: json['uid'],
      updated_at: json['updated_at'],
      created_at: json['created_at'],
      id: json['id'],
      user_info:
          json['user_info'] != null
              ? User_info.fromJson(json['user_info'])
              : null,
      apple_user:
          json['apple_user'] != null
              ? Apple_user.fromJson(json['apple_user'])
              : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'account': account,
      'status': status,
      'register_at': register_at,
      'refer': refer,
      'product_id': product_id,
      'partner_id': partner_id,
      'pitcher_id': pitcher_id,
      'app_id': app_id,
      'uid': uid,
      'updated_at': updated_at,
      'created_at': created_at,
      'id': id,
      'user_info': user_info?.toJson(),
      'apple_user': apple_user?.toJson(),
    };
  }
}

class Apple_user {
  int id;
  int app_id;
  String apple_user_id;
  int real_user_status;
  String email;
  String full_name;
  String created_at;
  String updated_at;

  Apple_user({
    required this.id,
    required this.app_id,
    required this.apple_user_id,
    required this.real_user_status,
    required this.email,
    required this.full_name,
    required this.created_at,
    required this.updated_at,
  });

  factory Apple_user.fromJson(Map<String, dynamic> json) {
    return Apple_user(
      id: json['id'],
      app_id: json['app_id'],
      apple_user_id: json['apple_user_id'],
      real_user_status: json['real_user_status'],
      email: json['email'],
      full_name: json['full_name'],
      created_at: json['created_at'],
      updated_at: json['updated_at'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'app_id': app_id,
      'apple_user_id': apple_user_id,
      'real_user_status': real_user_status,
      'email': email,
      'full_name': full_name,
      'created_at': created_at,
      'updated_at': updated_at,
    };
  }
}
